/**********************
 * Source Contact Panel
 */
AIR2.Source.Contact = function() {
    getStatus = function(sourceObj){
        var srcStatus = 'inactive';
        if ( sourceObj.src_status == 'A' ) {
            srcStatus = 'active';
        } 
        return '<span class="air2-source-contact-'+srcStatus+'-status">'+srcStatus+'</span>';
    }

    var pnl = new AIR2.UI.Panel({
        colspan: 2,
        title: AIR2.Format.sourceName(AIR2.Source.SUMMDATA.radix),
        iconCls: 'air2-icon-contactmethod',
        storeData: AIR2.Source.SUMMDATA,
        url: AIR2.Source.BASEURL,
        itemSelector: '.air2-source-contact',
        tpl: new Ext.XTemplate(
                '<table><tpl for=".">' +
                  '<tr class="air2-source-contact">' +
                    '<td class="photo">' +
                      '<img src="{AIR2.HOMEURL}/css/img/not_found.jpg" height="100"' +
                        'style="float: left; border: 5px solid #eee; margin: 0 10px 0 0;">' +
                    '</td>' +
                    '<td class="leftcol">' +
                      '<table class="address"><tpl for="SrcMailAddress">' +
                        '<tr>' +
                          '<td class="contact-label">Address 1</td>' +
                          '<td>{smadd_line_1}</td>' +
                        '</tr>' +
                        '<tr>' +
                          '<td class="contact-label">Address 2</td>' +
                          '<td>{smadd_line_2}</td>' +
                        '</tr>' +
                        '<tr>' +
                          '<td class="contact-label">City, State ZIP</td>' +
                          '<td>{smadd_city}, {smadd_state} {smadd_zip}</td>' +
                        '</tr>' +
                        '<tr>' +
                          '<td class="contact-label">Country</td>' +
                          '<td>{smadd_cntry}</td>' +
                        '</tr>' +
                      '</tpl></table>' +
                    '</td>' +
                    '<td class="rightcol">' +
                      '<table class="other">' +
                        '<tpl for="SrcPhoneNumber"><tr>' +
                          '<td class="contact-label">{sph_context}*</td>' +
                          '<td><b>{sph_number}</b></td>' +
                        '</tr></tpl>' +
                        '<tpl for="SrcEmail"><tr>' +
                          '<td class="contact-label">Email*</td>' +
                          '<td><b>{sem_email}</b></td>' +
                        '</tr></tpl>' +
                        '<tr>' +
                          '<td class="contact-label">Status</td>' +
                          '<td><div>{[this.srcStatus(values)]}</div></td>' +
                        '</tr>' +
                        '<tr>' +
                          '<td class="contact-label">Channel</td>' +
                          '<td><b>{[this.srcChannel(values)]}</b></td>' +
                        '</tr>' +
                      '</table>' +
                    '</td>' +
                  '</tr>' +
                '</tpl></table>',
                {
                    compiled: true,
                    disableFormats: true,
                    srcStatus: getStatus,
                    srcChannel: function(val) {
                        var ch = AIR2.Format.sourceChannel(val.src_channel);
                        return Ext.util.Format.ellipsis(ch, 30);
                    }
                }
        ),       
        editModal: {
            title: 'Contact Info',
            width: 500,
            allowAdd: false,
            tabLayout: true,
            items: {
                xtype: 'tabpanel',
                plain: true,
                activeTab: 0,
                items: [{
                    title: 'Source Info',
                    xtype: 'air2srcconinfo'
                },{
                    title: 'Email',
                    xtype: 'air2srcconemail',
                    srcUrl: AIR2.Source.BASEURL
                },{
                    title: 'Phone',
                    xtype: 'air2srcconphone',
                    srcUrl: AIR2.Source.BASEURL
                },{
                    title: 'Mailing',
                    xtype: 'air2srcconaddress',
                    srcUrl: AIR2.Source.BASEURL
                }],
                listeners: {
                    tabchange: function(tabpnl, tab) {
                        
                    }
                }
            }
        }
    });

    // give the info tab access to the record
    var coninfo = pnl.editModal.items.items[0];
    coninfo.record = pnl.store.getAt(0);
    pnl.store.proxy.setApi(Ext.data.Api.actions.update, AIR2.HOMEURL+'/source.json');

    return pnl;
}